#include "PreComplie.h"
#include "BTree.h"

namespace Behavior
{

XBTree::XBTree()
{
	OnCreateTree();
	assert(m_pRoot);
}

XBTree::~XBTree()
{
}

void XBTree::Release()
{
	delete this;
}

void XBTree::OnEvent(int eventID, void* pContext, int contextLen)
{
	XBTreeNode* pNode = static_cast<XBTreeNode*>(m_pRoot->Chilerens());
	while(pNode)
	{
		if(pNode->State() != XBTreeNode::eRunning)
			pNode->Active(eventID, pContext, contextLen);
		if(pNode->State() == XBTreeNode::eRunning)
			pNode->OnEvent(eventID, pContext, contextLen);
	}
}

void XBTree::OnCreateTree()
{
	m_pRoot = new XPrioritySelector(NULL);
	m_pRoot->AddChildren(new XActionNode(m_pRoot, new XConditionTrue()));
}

}
